package com.fita.wechat.dao;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.fita.entity.agent.Agent;
import com.fita.entity.agent.AgentApply;
import com.fita.entity.agent.AgentCompany;

import java.util.List;

/**
 * 
 * @author dan
 *
 */
@Dao("hibernate")
public interface AgentDao {
    
    /**
     * 
     * @param mobile
     * @return
     */
    @Query("FROM Agent WHERE disabled = false AND mobile = :mobile")
    public Agent load(@Variable("mobile") String mobile);
    
    /**
     * 
     * @param openid
     * @return
     */
    @Query("FROM Agent WHERE disabled = false AND openid = :openid")
    public Agent loadByOpenid(@Variable("openid") String openid);
    
    /**
     * 
     * @param mobile
     * @return
     */
    @Query("FROM AgentApply WHERE disabled = false AND mobile = :mobile")
    public AgentApply loadAgentApply(@Variable("mobile") String mobile);

    @Query("FROM Agent WHERE disabled = false AND company.primaryAgent = :primaryAgent")
    List<Agent> listSecondaryAgent(@Variable("primaryAgent") Agent primaryAgent);

    /**
     *
     * @param agentCompany
     * @return
     */
    @Query("FROM Agent WHERE disabled = false AND company = :company ")
    List<Agent> listByAgentCompany(@Variable("company") AgentCompany agentCompany);

    @Query("FROM Agent WHERE disabled = false AND company.companyName = :companyName ")
    List<Agent> listByAgentCompanyName(@Variable("companyName") String companyName);
}
